<?php

/**

 * Created by PhpStorm.

 * User: Administrator

 * Date: 2018/3/29 0029

 * Time: 16:03

 */



namespace app\home\controller;

use think\Db;



class Mxfz extends Base

{

        public function index(){
             $this->publicIndex();
                     $where['is_del']=0;
        $where['type']=1;
        $where['is_recom']=1;
        $where['sign']="pc";
         $where['style_id']=31;
        $data_mxfz = Db::name('zp')->where($where)->order('sort desc,id desc')->paginate(3,false,['query' => request()->param()]);
        
        $page = $data_mxfz->render();
        $this->assign('page',$page);
        $this->assign('data_mxfz',$data_mxfz);
             
              $id = intval(input('param.id'));

       
            return $this->fetch();    
        }

        
        public function mzkp() {
               $this->publicIndex();
             //每周客赏
        $where['is_del']=0;
        $where['is_del']=0;
        $where['is_recom']=1;
        $where['sign']="pc";
         $where['class_id']=36;
        $data_mzkp = Db::name('works')->where($where)->order('sort desc,id desc')->paginate(4,false,['query' => request()->param()]);
        
        $page = $data_mzkp->render();
        $this->assign('page',$page);
        $this->assign('data_mzkp',$data_mzkp);
        return $this->fetch();
        }
        
        
    //客片详情页

        public function details($id=0,$nid=0,$pid=0){
         $this->publicIndex();
            if(!empty($id)){

                $where['id']=$id;

                $where = [

                    'a.sign'=>"pc",

                    'a.is_del'=>0,

                    'a.is_show'=>1,

                    'a.id'=>$id

                ];

                $data_kp = Db::name('works')->alias('a')

                    ->where($where)

                    ->order('a.sort desc,a.id desc')

                    ->find();

                $works_pic = Db('works_pic')->where('pic_id','in',$data_kp['works_photo'])->field('works_pic,pic_id')->select();

                Db::name('works')->alias('a')

                    ->where('id',$id)

                    ->update(['click'=>$data_kp['click']+1]);

                $this->assign('works_pic',$works_pic);

                $this->assign('data_kp',$data_kp);

            }

            if(!empty($nid)){

                $where = [

                    'a.sign'=>"pc",

                    'a.is_del'=>0,

                    'a.is_show'=>1,

                ];



                $data_next = Db::name('works')->alias('a')

                    ->where($where)

                    ->where('a.id','>',$nid)

                    ->order('a.sort desc,a.id desc')

                    ->find();



                if($data_next){

                    $data_kp = Db::name('works')->alias('a')

                        ->where($where)

                        ->where('a.id',$data_next['id'])

                        ->order('a.sort desc,a.id desc')

                        ->find();

                    $works_pic = Db('works_pic')->where('pic_id','in',$data_kp['works_photo'])

                        ->field('works_pic,pic_id')->select();

                    Db::name('works')

                        ->where('id',$data_kp['id'])

                        ->update(['click'=>$data_kp['click']+1]);

                    $this->assign('data_next',$data_next);

                    $this->assign('works_pic',$works_pic);

                    $this->assign('data_kp',$data_kp);

                }else{

                    echo "<script>alert('没有下一篇了');history.back();</script>";die;

                }

            }

            if(!empty($pid)){

                $where = [

                    'a.sign'=>"pc",

                    'a.is_del'=>0,

                    'a.is_show'=>1,

                ];

                $data_prev = Db::name('works')->alias('a')

                    ->where($where)

                    ->where('a.id','<',$pid)

                    ->order('a.sort desc,a.id desc')

                    ->find();

                if($data_prev){

                    $data_kp = Db::name('works')->alias('a')

                        ->where($where)

                        ->where('a.id',$data_prev['id'])

                        ->order('a.sort desc,a.id desc')

                        ->find();

                    $works_pic = Db('works_pic')->where('pic_id','in',$data_kp['works_photo'])

                        ->field('works_pic,pic_id')->select();

                    Db::name('works')

                        ->where('id',$data_kp['id'])

                        ->update(['click'=>$data_kp['click']+1]);

                    $this->assign('data_prev',$data_prev);

                    $this->assign('works_pic',$works_pic);

                    $this->assign('data_kp',$data_kp);

                }else{

                    echo "<script>alert('没有下一篇了');history.back();</script>";die;

                }

            }

            //底部详情也广告

            $data_bannerfont = Db::name('banner')->where('is_del=0 and is_show=1 and sign="pc" and class_id=40')

                ->order('sort desc,id desc')->field('banner_img,out_link')->find();

            $this->assign('data_bannerfont',$data_bannerfont);

            //推荐客片

            $where = [

                'a.sign'=>"pc",

                'a.is_show'=>1,

                'a.is_del'=>0

            ];

            $data_kplist = Db::name('works')->alias('a')

                ->where($where)

                ->order('a.sort asc')

                ->paginate(12);

            $this->assign('data_kplist',$data_kplist);

            return $this->fetch();

        }
        
        public function fgyp_nr() {
             $id = intval(input('param.id'));
             if($id){
                 $where['id'] = $id;
                  $data_fgyp = Db::name('zp')->where($where)->select();

                  $arr = array();
                  foreach($data_fgyp as $k=>$v){
                     $arr = $data_fgyp[$k]['works_photo'];
                  }
                $new_arr = explode(',',$arr);
                $ret_data_fgyp = array();
                 foreach($new_arr as $v ){
                     $where_fgyp_new['pic_id'] = $v;
                     //$wheres['pic_id'] =array('in','695');
                     $new_data_fgyp = Db::name('works_pic')->where($where_fgyp_new)->select();
                    $ret_data_fgyp = array_merge($ret_data_fgyp,$new_data_fgyp);
                 }
            
                     $this->assign('ret_data_fgyp',$ret_data_fgyp);
                 return $this->fetch();
             }
             else{
              return $this->error('系统问题，请联系网络管理员');
             }
            
        }





}